<?php
namespace app\admin\controller;
use think\Db;
use app\admin\model\Evaluate as Evaluates;
class Evaluate extends Common
{
    protected $cModel;

    public function _initialize()
    {
         parent::_initialize();
         $this->cModel = new Evaluates;
    }
    public function index()
    {
        $where = [];
        if(input('get.serach')){
            $where['user_id|place_id'] = ['like','%'.input('get.serach').'%'];
        }

        $order = 'id desc';
        //查询场馆
        $dataList = Db::view('place')->field('id','0','place')->paginate('20',false,page_param());
        $result = [];
        foreach($dataList as $k =>$v){
            $result = $this->cModel->where(['place_id'=>$dataList[$k]['id']])->select();

        }


        // $dataList = $this->cModel->where($where)->order($order)->paginate('20',false,page_param());
        // $ids = [];
        // foreach ($dataList as$key=> $value) {
        //    $v->master;
        //    $v->cuser;
        // }
        $this->assign('dataList',$dataList);
        return $this->fetch();


    }

    //根据Place表中的id查询出该场馆下面所有的评论信息
    public function selectLists($id)
    {
        if(request()->isGet()){
            $id = input('id');
            $sql = "SELECT p.designation,eva.content,eva.user_id,eva.id,eva.grade,c.nickname,cu.telphone FROM gx_place p,gx_evaluate eva,gx_cuser_info c, gx_cuser cu WHERE p.id = eva.place_id AND c.uid = eva.user_id AND cu.id = c.uid AND p.id ={$id} ORDER BY eva.id";
             $dataList=Db::table('evaluate')->query($sql);
            $this->assign('dataList', $dataList);
            return $this->fetch('details');
        }


    }

    public function delete()
    {
        if(request()->isPost()){
            $id = input('id');
            if(isset($id) && !empty($id)){
                $id_arr = explode(',',$id);
                $where = ['id'=>['in',$id_arr]];
                $result = $this->cModel->where($where)->delete();
                if($result){
                    return ajaxReturn(lang('action_success'),url('index'));
                }else{
                    return ajaxReturn($this->cModel->getError());
                }
            }
        }
    }




}